@extends('manage.layout')

@section('content')
    <section class="content-header">
        <h1>
            编辑设计师信息
            <small>Preview</small>
        </h1>
        <ol class="breadcrumb">
            <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
            <li><a href="#">Designer</a></li>
            <li class="active">Designer Edit</li>
        </ol>
    </section>

    <section class="content">
        <div class="row">
            <!-- left column -->
            <div class="col-md-12">
                <!-- general form elements -->
                <div class="box box-primary">
                    <div class="box-header with-border">
                        <h3 class="box-title">内容</h3>
                    </div>
                    <!-- /.box-header -->
                    <!-- form start -->
                    <form action="{{ url('designer/designerUpdate') }}" method="post" role="form" style="width: 50%;">
                        {{csrf_field()}}
                        <input type="hidden" name="id" value="{{ $designer->id }}">
                        <div class="box-body">
                            <div class="form-group">
                                <label for="exampleInputPassword1">名称</label>
                                <input type="text" name="name" min="" value="{{ $designer->name }}" class="form-control" placeholder="名称">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">权重</label>
                                <input type="number" name="rank" min="0" value="{{ $designer->rank }}" class="form-control" placeholder="权重">
                            </div>
                            <div class="form-group">
                                <label for="exampleInputPassword1">描述</label>
                                <textarea id="editor_id" name="description" class="form-control"  placeholder="描述">{{ $designer->description }}</textarea>
                            </div>
                        </div>
                        <!-- /.box-body -->

                        <div class="box-footer">
                            <button type="submit" class="btn btn-primary">提交</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
@stop

@section('script')
    <script>
        //提交数据
        $(function() {
            var editor;
            KindEditor.ready(function(K) {
                editor = K.create('textarea[name="content"]', {
                    afterBlur: function () { this.sync(); },
                    resizeType : 1,
                    allowPreviewEmoticons : false,
                    allowImageUpload : false,
//                    syncType:form,
                    items : [
                        'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
                        'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
                        'insertunorderedlist', '|', 'emoticons',  'link']
                });


            });
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                }
            });
            $("form").submit(function(event) {
                event.preventDefault();
                var url = $(this).attr("action");
                var data = $("form").serialize();
                $.ajax({
                    url: url,
                    type: "POST",
                    data: data,
                    dataType: "json",
                    success: function(res) {
                        console.log(res);
                        if(res.code == 100) {
                            window.location.href = "/designer";
                            layer.msg(res.msg)
                        }
                        else {
                            layer.msg(res.msg)
                        }
                    }
                });
            });
        });
    </script>

@stop